const userServ = require('../service/userServ.js')
const JWT = require('../utils/jwt.js')

const userCtrl = {
  // 用户登录
  ulogin: async (ctx) => {
    let data = ctx.request.body
    const uid = await userServ.isExistServ( data)
    try {
      ctx.body = {
        code: 0,
        message: 'success',
        data: {
          userId: uid,
          token: JWT.generate({
            uid: uid, // 测试
          }, '1d')
        },
      }
    } catch (err) {
      console.error('用户登录失败', err)
    }
  },
  getContact: async (ctx) => {
    const userId = ctx.query.userId
    const res = await userServ.getContactServ(userId)
    ctx.body = {
      code: 0,
      msg: 'success',
      data:res
    }
  },
  // updateBaseinfo:async(ctx) => {
  //   const params = ctx.request.body
  //   await userServ.updateBaseinfoServ(params)
  //   ctx.body = {
  //     code: 0,
  //     msg: 'success',
  //   }
  // },
  editResume: async (ctx) => {
    const params = ctx.request.body
    await userServ.editResumeServ(params)
    ctx.body = {
      code: 0,
      msg: 'success',
    }
  },
  // 获取用户信息
  getUserinfo: async (ctx) => {
    const uid = ctx.query.userId
    const res = await userServ.getUserinfoServ(uid)
    console.log(res);
    ctx.body = {
      code: 0,
      msg: 'success',
      data: res
    }
  },
  // 反馈
  sendFeedback: async (ctx) => {
    const params = ctx.request.body
    await userServ.sendFeedbackServ(params)
    ctx.body = {
      code: 0,
      msg: 'success',
    }
  }
}

module.exports = userCtrl